

//Eli Elder
//remodel


#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h> 
#include <assert.h>
#include <math.h>
#include "rngs.h"

//set PRINTOUT to 0 to remove printfs out
#define PRINTOUT 1
#define ASSERTIVE 0

int checkRemodel(int card, int choice1, int choice2, int choice3, struct gameState *afterRemodelState, int handPos, int *bonus){
    int i;
    struct gameState beforeRemodelState;
    int returnVal;
    int trashCard;
    int player = whoseTurn(afterRemodelState);
    //copy so we can test if the remodel we can check
    memcpy(&beforeRemodelState, afterRemodelState, sizeof(struct gameState));
    //do the remodel function card
    returnVal = cardEffect(remodel, choice1, choice2, choice3, afterRemodelState, handPos, 0);
    
    trashCard = beforeRemodelState.hand[player][choice1];


    //inform user if cost is enough
    if((getCost(beforeRemodelState.hand[player][choice1]) + 2) < getCost(choice2)){
	printf("the cost of the choice1 + 2  is less than choice2\n");
    }
    
    //the before gains a card
    gainCard(choice2, &beforeRemodelState, 0, player);
    //we discard the handPos card
    discardCard(handPos, player, &beforeRemodelState, 0);
    
    //then we discard the card that is to be trashed
    for(i = 0; i < beforeRemodelState.handCount[player]; i++){
	if(beforeRemodelState.hand[player][i] == trashCard){
	    discardCard(i, player, &beforeRemodelState, 0);
	    break;
	}
    }
    
#if (PRINTOUT == 1)
    //if the full deck counts arent the same gain and discard messed up
    if(fullDeckCount(player, 0, &beforeRemodelState) < fullDeckCount(player, 0, afterRemodelState)){
	printf("The remodel state has more cards than the test\n");
    } else if(fullDeckCount(player, 0, &beforeRemodelState) > fullDeckCount(player, 0, afterRemodelState)){
	printf("The remodel state has less cards than the test\n");
    }
    
    //check the hand cards
    if(numHandCards(&beforeRemodelState) < numHandCards(afterRemodelState)){
	printf("The Remodel card has more hand cards than the test\n");
    } else if(numHandCards(&beforeRemodelState) > numHandCards(afterRemodelState)){
	printf("The Remodel card has less hand cards than the test\n");
    }
#endif
#if (ASSERTIVE == 1)
    //this will assert if something went wrong, those ifs above tell us what went wrong
    assert(returnVal == 0);
    //assert that the after RemodelCard state is the same as we expect it to be with the "before" that we made like the after
    assert(memcmp(&beforeRemodelState, afterRemodelState, sizeof(struct gameState)) == 0);
#endif

    return 0;
}

int main(){
    int i;
    int player = 1;
    int numDeck = 5;
    int bonus = 0;
    int numDiscard = 5;
    int numHand = 5;
    int initialized;
    int coppers[MAX_DECK];
    struct gameState theGameState;
    int kingCards[10] = {adventurer, council_room, feast, gardens, mine, remodel, smithy, village, baron, salvager};


    for(i = 0; i < MAX_DECK; i++){
        coppers[i] = copper;
    }

    //setup and initialize the state                                                                                                                                              
    memset(&theGameState, 23, sizeof(struct gameState));
    initialized = initializeGame(player, kingCards, 1, &theGameState);

    //assign the deck, hand, and discard                                                                                                                                          

    theGameState.discardCount[player] = numDiscard;
    theGameState.handCount[player] = numHand;
    theGameState.deckCount[player] = numDeck;

    //mem set the deck hand and discard                                                                                                                                            
    memcpy(theGameState.discard[player], coppers, sizeof(int) * MAX_DECK);
    memcpy(theGameState.hand[player], coppers, sizeof(int) * MAX_HAND);
    memcpy(theGameState.deck[player], coppers, sizeof(int) * MAX_HAND);

    theGameState.coins = 5;
    theGameState.whoseTurn = player;
    //check remodel

	printf("remdeled a gardens to a village\n");
    theGameState.playedCards[1] = 1;
    theGameState.playedCardCount=0;
    theGameState.hand[player][1] = gardens;
	theGameState.hand[player][2] = gardens;
    checkRemodel(remodel, 1, village, gold, &theGameState, 2, &bonus);
    
	printf("remodeled a smith to an adventurer\n");
    theGameState.playedCards[1] = 1;
    theGameState.playedCardCount=0;
    theGameState.hand[player][1] = smithy;
	theGameState.hand[player][2] = gardens;
    checkRemodel(remodel, 1, adventurer, gold, &theGameState, 2, &bonus);
    
	printf("remodeled a village to an adventurer\n");
    theGameState.playedCards[1] = 1;
    theGameState.playedCardCount=0;
    theGameState.hand[player][1] = village;
	theGameState.hand[player][2] = gardens;
    checkRemodel(remodel, 1, adventurer, gold, &theGameState, 2, &bonus);
	
	printf("remodeled a gold to an adventurer\n");
    theGameState.playedCards[1] = 1;
    theGameState.playedCardCount=0;
    theGameState.hand[player][1] = gold;
	theGameState.hand[player][2] = gardens;
    checkRemodel(remodel, 1, adventurer, gold, &theGameState, 2, &bonus);
	
	printf("remodeled a silver to an adventurer\n");
    theGameState.playedCards[1] = 1;
    theGameState.playedCardCount=0;
    theGameState.hand[player][1] = silver;
	theGameState.hand[player][2] = gardens;
    checkRemodel(remodel, 1, adventurer, gold, &theGameState, 2, &bonus);
	
    return 0;
}


